home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Multipane Dialogs Code / DD.c next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  2.1 KB  |  85 lines  |  [TEXT/MMCC]

  1. #include "MPDialogs.h"
  2. #include "DD.h"
  3.  
  4. /* Display a dialog which displays the values of the dialog items
  5.  * stored by the multi-pane dialog code
  6.  */
  7. void DialogDisplay(Handle theData)
  8. {
  9.     DialogPtr dlog;
  10.     short itemHit;
  11.     EventRecord theEvent;
  12.     DialogPtr whichDlog;
  13.     GrafPtr oldPort;
  14.     
  15.     if (!(dlog = GetNewDialog(500, NULL, (WindowPtr) -1))) return;
  16.     GetPort(&oldPort);
  17.     SetPort(dlog);
  18.     TextFont(geneva);
  19.     ShowWindow(dlog);
  20.     
  21.     do {
  22.         if(!GetNextEvent(everyEvent, &theEvent)) continue;
  23.         if(!IsDialogEvent(&theEvent)) continue;
  24.         (void) DialogSelect(&theEvent, &whichDlog, &itemHit);
  25.         
  26.         // Update the display of the dialog.
  27.         if (theEvent.what == updateEvt && whichDlog == dlog)
  28.             DoUpdate(dlog, theData);
  29.         
  30.         // If the user changed views, set it up for redraw
  31.         if (itemHit == 2)
  32.             InvalRect(&dlog->portRect);
  33.     } while (itemHit != 1);
  34.     
  35.     DisposeDialog(dlog);
  36.     SetPort(oldPort);
  37. }
  38.  
  39. /* Draw the dialog's contents.
  40.  */
  41. void DoUpdate(DialogPtr dlog, Handle theData)
  42. {
  43.     short i, iType, pane, val, err;
  44.     Handle iHandle;
  45.     Rect iRect;
  46.     Str255 theStr;
  47.     
  48.     pane = GetDItemValue(dlog, 2);
  49.     for(i=0; i<12; i++) {
  50.         // Draw item number
  51.         GetDItem(dlog, i*2+3, &iType, &iHandle, &iRect);
  52.         NumToString(i+1, theStr);
  53.         TextBox(&theStr[1], theStr[0], &iRect, 0);
  54.  
  55.         // Draw value of the item, or a message if an error was returned
  56.         GetDItem(dlog, i*2+4, &iType, &iHandle, &iRect);
  57.         if (err = GetMPDItem(theData, pane, i+1, (char *) &val, sizeof(short))) {
  58.             // Handle that string preference
  59.             if (err == keWrongSize) {
  60.                 long lval;
  61.                 if (!(err = GetMPDItem(theData, pane, i+1, (char *) &lval, sizeof(long)))) {
  62.                     NumToString(lval, theStr);
  63.                 } else if (err == keWrongSize) {
  64.                     err = GetMPDItem(theData, pane, i+1, (char *) theStr, sizeof(Str255));
  65.                 }
  66.             }
  67.             switch(err) {
  68.                 case keNullData:
  69.                     Pstrcpy(theStr, "\pNull Ptr!");
  70.                     break;
  71.                 case keBadPane:
  72.                     Pstrcpy(theStr, "\pBad Pane");
  73.                     break;
  74.                 case keBadItem:
  75.                     Pstrcpy(theStr, "\pBad Item");
  76.                     break;
  77.                 case keWrongSize:
  78.                     Pstrcpy(theStr, "\pWrong Size");
  79.                     break;
  80.             }
  81.         } else NumToString(val, theStr);
  82.         TextBox(&theStr[1], theStr[0], &iRect, 0);
  83.     }
  84. }
  85.